<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String path = request.getContextPath();
%>
<html lang="zh-cn">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no, email=no" />
<title>资源修改</title>
<link rel="stylesheet" href="<%=path %>/admin/css/pintuer.css">
<link rel="stylesheet" href="<%=path %>/admin/css/admin.css">
<script src="<%=path %>/admin/js/jquery.js"></script>
<script src="<%=path %>/admin/js/pintuer.js"></script>
<script src="<%=path %>/admin/js/pic.js"></script>
<script type="text/javascript" src="<%=path%>/admin/js/lrz.bundle.js"></script>
<script type="text/javascript" src="<%=path%>/admin/js/lrz.all.bundle.js"></script>
<script type="text/javascript" src="<%=path%>/admin/js/1.chunk.js"></script>
<script type="text/javascript" src="<%=path%>/admin/js/2.chunk.js"></script>
<script type="text/javascript" src="<%=path %>/admin/js/admin.js"></script>
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        ul li{
            list-style: none;
        }
        .morecheck {
            display: inline-block;
            width: 200px;
        }
        .morecheck input{
            width: 198px;
            height: 30px;
            padding-left: 10px;
        }
        .check-input {
            position: relative;
        }
        .check-input i {
            position: absolute;
            top: 50%;
            right: 10px;
            transform: translateY(-50%);
        }
        .choose-wrap {
            margin-top: 2px;
            display: none;
            width: 100%;
            position: relative;
            height: 171px;
            overflow-y: scroll;
            border: 1px solid #ccc;
        }
        .choose-wrap ul li{
            padding: 8px 10px;
            box-sizing: border-box;
            border-bottom: 1px solid #ccc;
            position: relative;
        }
        .choose-wrap ul li i{
            display: none;
            position: absolute;
            top: 50%;
            right: 10px;
            transform: translateY(-50%);
        }
        .choose-wrap ul li:hover{
            background: #eee;
        }
        .choose-wrap ul li:last-child {
            border-bottom: none;
        }
        .submit-panel {
            border-bottom: 0;
        }
        .submit-body-content {
            text-align: center;
        }
        .choose-wrap ul {
            padding: 0;
        }
    </style>
</head>
<body>
<div class="panel admin-panel submit-panel">
        <div class="body-content submit-body-content">
            <form id="planForm" method="post" class="form-x" action="<%=path %>/bUserInfo/updateGrade">
            <c:forEach items="${args}" var="item" varStatus="vs">  
                     <input type="hidden" value="${item}" name="openid[]" class="openid"/>
            </c:forEach>
                <div class="form-group">
                 <div class="morecheck">
				       <div class="check-input">
				           <input type="" name="" readonly value="资源分配">
				           <i class="fa fa-caret-down"></i>
				       </div>
				       <div class="choose-wrap">
				           <ul>
				           <c:forEach items="${bResources}" var="item" varStatus="vs">
				                 <li code="${item.id}">${item.name}<i class="fa fa-check"></i></li>
				          </c:forEach>
				           </ul>
				       </div>
				   </div>
                </div>
                <div class="form-group">
                    <div class="label">
                        <label></label>
                    </div>
                    <div class="field">
                        <button class="button bg-main icon-check-square-o" type="button"
                            onclick="javascript:sub();">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</body>
<script type="text/javascript" src="<%=path%>/admin/js/layer/layer.js" ></script>
<script type="text/javascript">
	$(".check-input").click(function() {
	    $(this).next().toggle();
	})
	var valueList = new Array();       
	$(".choose-wrap ul li").each(function() {
	    var flag = true;
	    $(this).click(function() {
	        if(flag) {
	            $(this).children().show();
	            flag = false;
	            valueList.push($(this).attr("code"))
	            console.log(valueList)
	        }else {                 
	            $(this).children().hide();
	            flag = true;
	            for(var i = 0; i < valueList.length; i++) {
	                if(valueList[i] == $(this).attr("code")) {
	                    valueList.splice(i,1)
	                }
	            }
	            console.log(valueList);
	           /*  $(this).parent().parent().prev().children().attr("value",valueList) */
	        }
	    })
	})
	$(function(){
	    var subTag = '${subTag}';
	    if(subTag==1){
	        layer.msg('操作成功！');
	    }else if(subTag== 2){
	        layer.msg('系统忙！');
	    }
	});

	var flag=true;
	function sub(){
		if(true){
			falg=false;
		if(valueList==""){
			flag=true;
            layer.msg("请选择需要分配的资源");
        }else{
             var params = new Object();
             params.resourceId=valueList;
             var arrayObj = new Array();
             $(".openid").each(function(){
                 arrayObj.push($(this).val());
             })
             params.adId=arrayObj;
               $.ajax({ 
                    type:"post",
                    url:"<%=path %>/devops/updateGrade",
                    data:params,
                    dataType: "json",  
                    cache: false,  
                    error: function(){
                    	flag=true;
                        alert("系统忙...");
                    },
                    success: function(data){
                    	flag=true;
                        var json=eval(data);
                        layer.msg(json.msg);
                    }
               })
         }
		}
		
	};
	
</script>
</html>